package listdemo;

import jdk.swing.interop.SwingInterOpUtils;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

/**
 * @Author 12629
 * @Description：
 */
class Book {

}
public class Test {

    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);

        System.out.println(list);

        System.out.println("=======for循环========");
        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i)+" ");
        }
        System.out.println();

        System.out.println("=======for each 循环========");
        for(Integer x : list) {
            System.out.print(x+" ");
        }
        System.out.println();

        System.out.println("=======迭代器遍历1========");
        Iterator<Integer> it =  list.iterator();
        while (it.hasNext()) {
            System.out.print(it.next()+" ");//1 2 3 4
        }
        System.out.println();
        System.out.println("=======迭代器遍历2========");
        ListIterator<Integer> lit =  list.listIterator();
        while (lit.hasNext()) {
            System.out.print(lit.next()+" ");//1 2 3 4
        }
        System.out.println();

        System.out.println("=======迭代器遍历3========");
        ListIterator<Integer> litPrev =  list.listIterator(list.size());
        while (litPrev.hasPrevious()) {
            System.out.print(litPrev.previous()+" ");
        }
        System.out.println();

    }
    public static void main3(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        System.out.println(list);

        List<Integer> listTmp = list.subList(1,3);// 2 3
        System.out.println(listTmp);
        System.out.println("=====================");
        listTmp.set(0,99);
        System.out.println("listTmp： "+listTmp);
        System.out.println("list: "+ list);



       /* list.remove(new Integer(1));

        System.out.println(list);
*/

        /*ArrayList<Integer> list2 = new ArrayList<>();
        list2.add(11);
        list2.add(22);
        list2.add(33);
        list.addAll(list2);
*/

        /*ArrayList<String> list3 = new ArrayList<>();

        list.addAll(list3);*/




    }
    public static void main2(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(0);
        list.add(1);
        list.add(2);
        list.add(3);

        list.add(1,99);


        ArrayList<Book> bookList = new ArrayList<>();

    }
    public static void main1(String[] args) {
        MyArrayList myArrayList = new MyArrayList();
        myArrayList.add(1);
        myArrayList.add(2);
        myArrayList.add(3);

        myArrayList.display();

        System.out.println(myArrayList.contains(3));//true

        System.out.println(myArrayList.get(1));//2

        myArrayList.set(10,99);

        myArrayList.display();



    }
}
